#ifndef CELLMAINWINDOW_H
#define CELLMAINWINDOW_H

#include <QMainWindow>
#include "glwidget.h"
#include "stylesheet.h"
#include "commands.h"
#include <vector>

QT_BEGIN_NAMESPACE
class QMenu;
class QAction;
class QPlainTextEdit;
class QButtonGroup;
class QToolButton;
class QAbstractButton;
class QToolBar;
class QScrollArea;
class QToolBox;
class QLabel;
class QLineEdit;
class QDoubleSpinBox;
class QStatusBar;
class QGridLayout;
class QPushButton;
class QDockWidget;
class QMessageBox;
class QListWidget;
class QListWidgetItem;
class QUndoStack;
QT_END_NAMESPACE

//!  A QMainWindow class.
/*!
  It is class to construct main UI.
*/

class CellMainWindow : public QMainWindow
{
    Q_OBJECT
    
public:
    CellMainWindow();
    ~CellMainWindow();

protected:
    void keyPressEvent(QKeyEvent *event);
    void keyReleaseEvent(QKeyEvent *event);
    bool eventFilter(QObject *target, QEvent *event);
    void mousePressEvent(QMouseEvent *event);
    void mouseReleaseEvent(QMouseEvent *event);
    void mouseMoveEvent(QMouseEvent *event);

private slots:
    //Main Menu Slots
    void newScene();
    void importXML();
    void importSBML();
    void save();
    void cut();
    void copy();
    void paste();
    void select();
    void surfaceConstructionSlot();
    void editMeshSlot();
    void unionSlot();
    void subtractSlot();
    void intersectSlot();
    void inputSlot(int type);

    void transformToolGroupClicked(QAbstractButton *button);
    void viewToolGroupClicked(QAbstractButton *button);
    void cameraToolGroupClicked(QAbstractButton *button);
    void paintToolGroupPressed(QAbstractButton *button);
    void paintToolGroupReleased(QAbstractButton *button);
    void disolayModeToolGroupClicked(QAbstractButton *button);
    void meshEditModeGroupClicked(QAbstractButton *button);
    void resetButtonPressed();
    void deleteButtonPressed();
    void selectClicked(QListWidgetItem *current, QListWidgetItem *previous);
    void rightClickMenuSlot(QPoint pos);
    void deleteSelectedObjectSlot();
    void generateMeshSlot();

    void setTranslateX(QString l);
    void setTranslateY(QString l);
    void setTranslateZ(QString l);
    void setRotateX(QString l);
    void setRotateY(QString l);
    void setRotateZ(QString l);
    void setScaleX(QString l);
    void setScaleY(QString l);
    void setScaleZ(QString l);

    void setSphereRadius(QString l);
    void setSphereHeightSeg(QString l);
    void setSphereAxisSeg(QString l);

    void setCylinderRadius(QString l);
    void setCylinderHeight(QString l);
    void setCylinderHeightSeg(QString l);
    void setCylinderAxisSeg(QString l);

    void setCubeWidth(QString l);
    void setCubeHeight(QString l);
    void setCubeDepth(QString l);
    void setCubeWidthSeg(QString l);
    void setCubeHeightSeg(QString l);
    void setCubeDepthSeg(QString l);

private:

    void createMenuActions();
    void createMenus();
    void createRightClickMenu();
    void createTransformToolGroup();
    void createViewToolGroup();
    void createCameraToolGroup();
    void createDisplayModeToolGroup();
    void createPaintToolGroup();
    void createObjectTabWidget();
    void createFileToolBar();
    void createImformationWidget();
    void createOpenGLWindow();
    void createStatusBar();
    void createLeftPart();
    void createRightPart();
    void createToolButton(QWidget *widget, QButtonGroup *buttonGroup, QToolButton *button,
                          const QString &text, const QString &image,
                          const int x, const int y, const int w, const int h, bool checked);
    void createToolButton1(QWidget *widget, QToolButton *button,
                           const QString &text, const QString &image,
                           const int x, const int y, const int w, const int h, bool checked);
    void createMeshEditWidget();
    void createSelectWidget();

    QAction *surfaceConstructionAction;
    QAction *editMeshAction;
    //Layout
    QWidget *centralWidget;
    QGridLayout *centerLayout;
    QWidget *leftPart;
    QWidget *rightPart;

    //Main Menu
    QMenu *fileMenu;
    QMenu *editMenu;
    QMenu *displayMenu;
    QMenu *simulationMenu;
    QMenu *pluginsMenu;
    QMenu *helpMenu;
    QAction *newSceneAction;
    QAction *importXMLAction;
    QAction *importSBMLAction;
    QAction *saveAction;
    QAction *undoAction;
    QAction *redoAction;
    QAction *cutAction;
    QAction *copyAction;
    QAction *pasteAction;
    QAction *selectAction;

    QMenu *booleanMenu;
    QAction *unionAction;
    QAction *subtractAction;
    QAction *intersectAction;

    //Right Click Menu
    QMenu *rightClickMenu;
    QAction *cutActionRC;
    QAction *copyActionRC;
    QAction *pasteActionRC;
    QAction *editMeshActionRC;
    QAction *deleteActionRC;
    QAction *generateMeshActionRC;


    //File and Edit Tool Bar
    QToolBar *fileToolBar;
    QAction *newSceneActionTB;
    QAction *importXMLActionTB;
    QAction *importSBMLActionTB;
    QAction *saveActionTB;
    QAction *undoActionTB;
    QAction *redoActionTB;
    QAction *cutActionTB;
    QAction *copyActionTB;
    QAction *pasteActionTB;


    //Transform Tool Group
    QButtonGroup *transformToolGroup;
    QToolButton *selectButton;
    QToolButton *translateButton;
    QToolButton *rotateButton;
    QToolButton *scaleButton;
    QToolButton *ctrlPointsButton;
    QWidget *transformToolWidget;

    //View Tool Group
    QButtonGroup *viewToolGroup;
    QToolButton *perspectiveViewButton;
    QToolButton *fourViewButton;
    QToolButton *topViewButton;
    QToolButton *rightViewButton;
    QToolButton *frontViewButton;
    QToolButton *planeBaseViewButton;
    QPushButton *resetViewButton;
    QWidget *viewToolWidget;

    //Camera Tool Group
    QButtonGroup *cameraToolGroup;
    QToolButton *cameraMoveButton;
    QToolButton *cameraRotateButton;
    QToolButton *cameraZoomButton;
    QWidget *cameraToolWidget;

    //Display Mode Tool Group
    QButtonGroup *dispalyModeToolGroup;
    QToolButton *pointButton;
    QToolButton *lineButton;
    QToolButton *triangleButton;
    QWidget *displayModeToolWidget;

    //Paint Tool Group
    QButtonGroup *paintToolGroup;
    QToolButton *paintButton1;
    QToolButton *paintButton2;
    QToolButton *paintButton3;
    QToolButton *paintButton4;
    QToolButton *paintButton5;
    QToolButton *paintButton6;
    QToolButton *paintButton7;
    QToolButton *paintButton8;
    QToolButton *paintButton9;
    QWidget *paintToolWidget;

    //Object Tool Group
    QWidget *objectToolWidget;
    QWidget *cellWidget;
    QWidget *basementMembraneWidget;
    QWidget *bloodVesselWidget;
    QWidget *ECMWidget;
    QWidget *sphereInputWidget;
    QWidget *cylinderInputWidget;
    QWidget *cubeInputWidget;
    QWidget *planeInputWidget;
    QWidget *inputWidget;
    QToolBox *objectToolBox;

    //Object Transform Imformation
    QWidget *imformationWidget;
    QLabel *objectNameLabel;
    QLabel *translateXLabel;
    QLabel *translateYLabel;
    QLabel *translateZLabel;
    QLabel *rotateXLabel;
    QLabel *rotateYLabel;
    QLabel *rotateZLabel;
    QLabel *scaleXLabel;
    QLabel *scaleYLabel;
    QLabel *scaleZLabel;
    QLineEdit *translateXEdit;
    QLineEdit *translateYEdit;
    QLineEdit *translateZEdit;
    QLineEdit *rotateXEdit;
    QLineEdit *rotateYEdit;
    QLineEdit *rotateZEdit;
    QLineEdit *scaleXEdit;
    QLineEdit *scaleYEdit;
    QLineEdit *scaleZEdit;

    GLWidget *perspectiveWidget;
    QScrollArea *perspectiveWidgetArea;

    //Mesh Edit
    QDockWidget* editMeshDockWidget;
    QWidget* editMeshWidget;
    QButtonGroup *meshEditModeGroup;
    QToolButton *pointsEditButton;
    QToolButton *facesEditButton;

    //Select Widget;
    QDockWidget* selectDockWidget;
    QWidget* selectWidget;
    QListWidget* selectListWidget;

    QUndoStack *undoStack;
    QUndoCommand *recCommand;
};

#endif // CELLMAINWINDOW_H
